// Tierless
// Copyright © 2010 Alphora
// This file is licensed under a modified BSD-license (see tierless_license.txt).
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace Tierless.Framework.EntityTypes
{
	/// <summary>
	/// Represents a key definition for an entity type.
	/// </summary>
	[DataContract]
	public class EntityKey : NamedEntityTypeObject
	{
		/// <summary>
		/// Initializes a new instance of the EntityKey class.
		/// </summary>
		/// <param name="name">The name of the key.</param>
		public EntityKey(string name)
			: base(name)
		{
			_columns = new EntityTypeColumnReferenceCollection();
		}

		/// <summary>
		/// Initializes a new instance of the EntityKey class.
		/// </summary>
		/// <param name="name">The name of the key.</param>
		/// <param name="columnNames">The names of the columns in the key.</param>
		public EntityKey(string name, IEnumerable<string> columnNames)
			: base(name)
		{
			_columns = new EntityTypeColumnReferenceCollection(columnNames);
		}

		/// <summary>
		/// Gets or sets whether or not the key is primary.
		/// </summary>
		[DataMember]
		public bool IsPrimary { get; set; }

		/// <summary>
		/// Gets or sets whether or not the key is temporal.
		/// </summary>
		[DataMember]
		public bool IsTemporal { get; set; }

		[DataMember]
		private EntityTypeColumnReferenceCollection _columns;

		/// <summary>
		/// Gets the set of columns involved in the key.
		/// </summary>
		public EntityTypeColumnReferenceCollection Columns
		{
			get { return _columns; }
		}

		/// <summary>
		/// Returns a string representation of the entity key.
		/// </summary>
		/// <returns>A string representation of the entity key.</returns>
		public override string ToString()
		{
			return String.Format("EntityKey: Name={0}, IsPrimary={1}, Columns={2};", Name, IsPrimary, Columns);
		}
	}
}